﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModelDinhMuc.Model;
namespace TinhNguyenVatLieuSanBay
{
    public partial class FrmDanhMuc : Form
    {
        
        public static FrmDanhMuc frmdanhmuc = null;
        public FrmDanhMuc()
        {
            InitializeComponent();
            frmdanhmuc = this;
            InitDMcha();
        }
        DINHMUCSANBAYDB db = new DINHMUCSANBAYDB();
        public void InitDMcha()
        {
            IList<Catalog> lst;
            lst = db.selectcatalogParent().ExecuteTypedList<Catalog>();
            catalogBindingSource.DataSource = lst;
        }

        public void InitDMCon(long id)
        {
            IList<Catalog> lst;
            lst = db.selectcatalogHaveParent(id).ExecuteTypedList<Catalog>();
            if (lst.Count > 0)
            {
                catalogConBindingSource.DataSource = lst;
            }
        }

        private void FrmDanhMuc_FormClosed(object sender, FormClosedEventArgs e)
        {
            frmdanhmuc = null;
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void gvdanhmuccha_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                long id = long.Parse(gvdanhmuccha.CurrentRow.Cells["idDataGridViewTextBoxColumn"].ToString());
                InitDMCon(id);
            }
            catch (Exception ex)
            {

            }
        }
    }
}
